//
//  NSString+Extension.h
//  TableDemo
//
//  Created by jutuo on 2020/3/19.
//  Copyright © 2020 jutuo. All rights reserved.
//


#import <Foundation/Foundation.h>
#import "NSData+Extension.h"
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN

@interface NSString (Extension)
#pragma mark - 检查字符串
// 是否存在值:
- (BOOL)isNotNull;

// 去掉所有的空格
- (NSString *)trimAllWhitespace;

// 检查姓名（待检验）
- (BOOL)checkName;

// 检查手机号
- (BOOL)checkPhoneNum;  // 手机号
- (BOOL)checkTelNumber; // 座机号(需要验证）

// 检查Email
- (BOOL)checkEmail;

// 检查车牌号
- (BOOL)checkNumAndChar;

// 检查纯数字
- (BOOL)checkNum;
// 检查数字和字母
- (BOOL)checkNumAndString;
//6-20位字母和数字组合
- (BOOL)checkNumAndString6_20;
// 检测字符串包含某个字符串，适用于IOS7，和IOS8
- (BOOL)myContainsString:(NSString *)other;
//是否包含标点
- (BOOL)containPunctuation;
//过滤掉标点符号
- (NSString *)disablePunctuation;
// 是否包含表情
- (BOOL)isContainsEmoji;
//过滤掉表情
- (NSString *)disableEmoji;
/**
 * 按正则表达式进行过滤
 */
- (NSString *)disableRegEx:(NSString *)reg;
//是否是网络地址
- (BOOL)isUrlAddress;


#pragma mark - Drawing

- (CGSize)sizeForFont:(UIFont *)font size:(CGSize)size mode:(NSLineBreakMode)lineBreakMode;

- (CGFloat)widthForFont:(UIFont *)font;

- (CGFloat)heightForFont:(UIFont *)font width:(CGFloat)width;

#pragma mark - Utilities
+ (NSString *)stringWithUUID;

+ (NSString *)stringWithUTF32Char:(UTF32Char)char32;

- (nullable NSNumber *)numberValue;

/**
 Returns an NSData using UTF-8 encoding.
 */
- (nullable NSData *)dataValue;
@end


@interface NSString (Hash)
#pragma mark - 加密
/**
 Returns a lowercase NSString for md2 hash.
 */
- (nullable NSString *)md2String;

/**
 Returns a lowercase NSString for md4 hash.
 */
- (nullable NSString *)md4String;

/**
 Returns a lowercase NSString for md5 hash.
 */
- (nullable NSString *)md5String;

/**
 Returns a lowercase NSString for sha1 hash.
 */
- (nullable NSString *)sha1String;

/**
 Returns a lowercase NSString for sha224 hash.
 */
- (nullable NSString *)sha224String;

/**
 Returns a lowercase NSString for sha256 hash.
 */
- (nullable NSString *)sha256String;

/**
 Returns a lowercase NSString for sha384 hash.
 */
- (nullable NSString *)sha384String;

/**
 Returns a lowercase NSString for sha512 hash.
 */
- (nullable NSString *)sha512String;

/**
 Returns a lowercase NSString for hmac using algorithm md5 with key.
 @param key The hmac key.
 */
- (nullable NSString *)hmacMD5StringWithKey:(NSString *)key;

/**
 Returns a lowercase NSString for hmac using algorithm sha1 with key.
 @param key The hmac key.
 */
- (nullable NSString *)hmacSHA1StringWithKey:(NSString *)key;

/**
 Returns a lowercase NSString for hmac using algorithm sha224 with key.
 @param key The hmac key.
 */
- (nullable NSString *)hmacSHA224StringWithKey:(NSString *)key;

/**
 Returns a lowercase NSString for hmac using algorithm sha256 with key.
 @param key The hmac key.
 */
- (nullable NSString *)hmacSHA256StringWithKey:(NSString *)key;

/**
 Returns a lowercase NSString for hmac using algorithm sha384 with key.
 @param key The hmac key.
 */
- (nullable NSString *)hmacSHA384StringWithKey:(NSString *)key;

/**
 Returns a lowercase NSString for hmac using algorithm sha512 with key.
 @param key The hmac key.
 */
- (nullable NSString *)hmacSHA512StringWithKey:(NSString *)key;

/**
 Returns a lowercase NSString for crc32 hash.
 */
- (nullable NSString *)crc32String;

#pragma mark - Encode and decode
///=============================================================================
/// @name Encode and decode
///=============================================================================

/**
 Returns an NSString for base64 encoded.
 */
- (nullable NSString *)base64EncodedString;

/**
 Returns an NSString from base64 encoded string.
 @param base64Encoding The encoded string.
 */
+ (nullable NSString *)stringWithBase64EncodedString:(NSString *)base64EncodedString;

/**
 URL encode a string in utf-8.
 @return the encoded string.
 */
- (NSString *)stringByURLEncode;

/**
 URL decode a string in utf-8.
 @return the decoded string.
 */
- (NSString *)stringByURLDecode;

/**
 Escape common HTML to Entity.
 Example: "a<b" will be escape to "a&lt;b".
 */
- (NSString *)stringByEscapingHTML;

@end

@interface NSString (Path)
/**
 *  获取文档的绝对路径。
 *  @return Document path.
 */
+ (NSString *)documentPath;

/**
*    获取tmp的绝对路径。
*
*    @return Tmp path
*/
+ (NSString *)tmpPath;

/**
*    获取高速缓存的绝对路径。
*
*    @return Cache absolute path
*/
+ (NSString *)cachePath;

///  追加文档目录
- (NSString *)appendDocumentPath;
///  追加缓存目录
- (NSString *)appendCachePath;
///  追加临时目录
- (NSString *)appendTempPath;


@end
NS_ASSUME_NONNULL_END
